import { Menu } from 'siyuan'

/**
 * 菜单管理器
 * 负责创建和管理插件菜单
 */
export class MenuManager {
  /**
   * 显示插件主菜单
   * @param event 鼠标事件
   * @param callbacks 菜单项回调函数
   */
  static showMainMenu(event: MouseEvent, callbacks: {
    onShowForm: () => void
    onLoadDoc: () => void
    onOptimizeTitle: () => void
    onShowHelp: () => void
    onShowAbout: () => void
  }) {
    const menu = new Menu('插件菜单')
    
    // 主要功能菜单项
    menu.addItem({
      icon: 'iconSettings',
      label: '测试表单',
      click: callbacks.onShowForm
    })
    
    menu.addItem({
      icon: 'iconInfo',
      label: '获取当前文档',
      click: callbacks.onLoadDoc
    })
    
    menu.addItem({
      icon: 'iconEdit',
      label: '优化标题',
      click: callbacks.onOptimizeTitle
    })
    
    // 分隔线
    menu.addSeparator()
    
    // 辅助功能菜单项
    menu.addItem({
      icon: 'iconHelp',
      label: '使用帮助',
      click: callbacks.onShowHelp
    })
    
    menu.addItem({
      icon: 'iconInfo',
      label: '关于插件',
      click: callbacks.onShowAbout
    })
    
    // 获取触发按钮的位置并显示菜单
    const rect = (event.target as HTMLElement).getBoundingClientRect()
    menu.open({
      x: rect.left,
      y: rect.bottom,
      isLeft: true
    })
  }
}
